package com.qiangesoft.im.config;

import com.baomidou.mybatisplus.core.handlers.MetaObjectHandler;
import com.qiangesoft.im.auth.UserUtil;
import org.apache.ibatis.reflection.MetaObject;
import org.springframework.stereotype.Component;

import java.util.Date;

/**
 * 自动填充创建修改相关字段
 *
 * @author qiangesoft
 * @date 2024-01-08
 */
@Component
public class CustomMetaObjectHandler implements MetaObjectHandler {

    @Override
    public void insertFill(MetaObject metaObject) {
        setFieldValByName("createBy", UserUtil.getUserId(), metaObject);
        setFieldValByName("createTime", new Date(), metaObject);
    }

    @Override
    public void updateFill(MetaObject metaObject) {
        setFieldValByName("updateBy", UserUtil.getUserId(), metaObject);
        setFieldValByName("updateTime", new Date(), metaObject);
    }
}
